import { dirname } from 'path';
import process from 'process'
import fs from 'fs'
import path from 'path'
import { Asyncer, BuildGame, CopyDir, CopyFile, DirForeach, FindProjectRoot, MkDir, RmDir, ZipDir } from './src/utils.mjs';
import { BuildConfig, BuildInfo } from './src/classes.mjs';
const __dirname = dirname(process.argv[1]);
const rootPath = FindProjectRoot();
const buildPath = path.resolve(rootPath, "build/web-mobile");

const info = new BuildInfo();
if (fs.existsSync(path.resolve(buildPath, "build.info"))) {
    Object.assign(info, JSON.parse(fs.readFileSync(path.resolve(buildPath, `build.info`)).toString()));
}
else {
    console.warn("还没打包，请先执行build.mjs");
    process.exit(0);
}


const useUID = process.argv[2];
let uid = "";
if (useUID) {
    uid = `${Math.floor(Math.random() * 9999999)}`;
    console.log(`使用UID: ${uid}`);
}

await BuildGame(`build/games-${info.target}`, uid, info, true);
await Asyncer.awaitAllJobDone();
process.exit(0);